<?php
namespace App\Models\Data;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations;
use Dcat\Admin\Traits\HasDateTimeFormatter;
class ClickLearn extends Model
{
    use HasDateTimeFormatter;
    protected $table = 'click_learns';
    protected $fillable = ['id','content','translation','phonetic','audio_url','image_url',
        'sentence','sentence_translation','practice_translation','type','is_download','is_recite','word_blanks','spell_audio','option','option_order'];
    const TYPE_SENTENCE=0;
    const TYPE_WORD=1;
    const TYPE_OTHER=2;
    const TYPE_WORD_GROUP=3;
    public static array $typeMap = [
        self::TYPE_SENTENCE=>'句子',
        self::TYPE_WORD=>'单词',
        self::TYPE_OTHER=>'非跟读',
        self::TYPE_WORD_GROUP=>'词组',
    ];
    public function sentence_translate():Relations\hasOne
    {
        return $this->hasOne(ClickLearn::class,'id','sentence');
    }
    public function spells(): Relations\hasMany
    {
        return $this->hasMany(ClickLearnSpell::class)->where('is_option',ClickLearnSpell::OPTION_OFF);
    }
    public function spell_options(): Relations\hasMany
    {
        return $this->hasMany(ClickLearnSpell::class)->where('is_option',ClickLearnSpell::OPTION_TRUE)->orderBy('time');
    }
}
